export class List<T> extends Array<T> {

    private items: T[];

    constructor(...args) {
        super();
        this.items = new Array(...args);
        Object.defineProperty(this, "items", { enumerable: false });
    }

    Add(item: T) {
        this.items.push(item);
    }

    AddRange(list: List<T>): void {
        if (list.items) {
            this.items.push(...list.items);
        } else {
            this.items.push(...list);
        }
    }

    Remove(item: T) {
        const index = this.items.indexOf(item);
        this.RemoveAt(index);
    }

    RemoveAt(index: number) {
        if (index !== -1) {
            this.items.splice(index, 1);
        }
    }

    Get(index: number): T {
        return this.items[index];
    }

    Set(index: number, item: T) {
        this.items[index] = item;
    }

    Clear() {
        this.items = [];
    }

    FindIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number {
        return this.items.findIndex(predicate);
    }

    get Count(): number {
        return this.items.length;
    }

    ToArray(): T[] {
        return this.items.slice();
    }

}